define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
    var Controller = {
        index: function () {
            //
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'statistics/index',
                    table: '',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {field: 'id', title: 'ID', operate: false},
                        {field: 'store_name', title: '门店'},
                        {field: 'reserve_num', title: '总预约次数'},
                        {field: 'reserve_done_num', title: '完成预约次数'},
                        {field: 'reserve_cancel_num', title: '取消预约次数'},
                        {field: 'total_reserve_hours', title: '累计出租时长（小时）'},
                    ]
                ],
                searchFormVisible: true,
                search: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        storerenttime: function () {

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'statistics/storerenttime',
                    table: '',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {field: 'id', title: 'ID'},
                        {field: 'key', title: '周期'},
                        {field: 'reserve_num', title: '总预约次数'},
                        {field: 'done_num', title: '完成次数'},
                        {field: 'cancel_num', title: '取消次数'},
                        {field: 'reserve_hour', title: '总预约时长（小时）'},
                        {field: 'done_hour', title: '完成时长（小时）'},
                        {field: 'cancel_hour', title: '取消时长（小时）'},
                        {field: 'all_income', title: '总预约金额'},

                        {field: 'pay_direct', title: '直接支付'},
                        {field: 'pay_direct_done', title: '直接支付（完成）'},
                        {field: 'pay_direct_cancel', title: '直接支付(取消)'},
                        {field: 'direct_income', title: '直接金额'},

                        {field: 'pay_balance', title: '余额支付'},
                        {field: 'pay_balance_done', title: '余额支付（完成）'},
                        {field: 'pay_balance_cancel', title: '余额支付(取消)'},
                        {field: 'balance_income', title: '余额金额'},

                        {field: 'pay_card', title: '卡券支付'},
                        {field: 'pay_card_done', title: '卡券支付（完成）'},
                        {field: 'pay_card_cancel', title: '卡券支付(取消)'},
                        {field: 'card_income', title: '卡券金额'},

                        {field: 'pay_dzmt', title: '大众美团支付'},
                        {field: 'pay_dzmt_done', title: '大众美团支付（完成）'},
                        {field: 'pay_dzmt_cancel', title: '大众美团支付(取消)'},
                        {field: 'dzmt_income', title: '大众美团金额'},


                        {field: 'pay_combine', title: '组合支付'},
                        {field: 'pay_combine_done', title: '组合支付（完成）'},
                        {field: 'pay_combile_cancel', title: '组合支付(取消)'},
                        {field: 'combine_card_income', title: '组合卡券支付金额'},
                        {field: 'combine_balance_income', title: '组合余额支付金额'},
                        {field: 'combine_direct_income', title: '组合直接支付金额'},
                    ]
                ],
                searchFormVisible: true,
                search: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        storehourdistribution: function () {

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'statistics/storehourdistribution',
                    table: '',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {field: 'id', title: 'ID'},
                        {field: 'key', title: '时间pill'},
                        {field: 'all_count', title: '预约总次数'},
                        {field: 'all_fee', title: '预约总金额'},
                        {field: 'direct_count', title: '直接预约'},
                        {field: 'direct_fee', title: '直接金额'},
                        {field: 'balance_count', title: '余额预约'},
                        {field: 'balance_fee', title: '余额金额'},
                        {field: 'card_count', title: '卡券预约'},
                        {field: 'card_fee', title: '卡券金额'},
                        {field: 'dzmt_count', title: '大众美团预约'},
                        {field: 'dzmt_fee', title: '大众美团金额'},
                    ]
                ],
                searchFormVisible: true,
                search: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        renttimedistribution: function () {

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'statistics/rentTimeDistribution',
                    table: '',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {field: 'id', title: 'ID'},
                        {field: 'key', title: '租次数'},
                        {field: 'count', title: '人数', operate: false, formatter: function (value, row, index) {
                                url = "statistics/userslist?id=" + row.user_ids_str;
                                this.url = url;
                                return Table.api.formatter.addtabs.call(this, value, row, index);
                            }},
                        {field: 'allcount', title: '总次数'},
                        {field: 'allhour', title: '总小时数'},
                    ]
                ],
                searchFormVisible: true,
                search: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        storeweekdistribution: function () {

            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'statistics/storeWeekDistribution',
                    table: '',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {field: 'id', title: 'ID'},
                        {field: 'key', title: '星期'},
                        {field: 'count', title: '次数', operate: false},
                        {field: 'hour', title: '总小时数'},
                    ]
                ],
                searchFormVisible: true,
                search: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        userslist: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'statistics/userslist',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'user.id',
                // searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), sortable: true, operate: 'IN'},
                        {field: 'username', title: __('Username'), operate: false},
                        {field: 'nickname', title: __('Nickname'), operate: false},
                        {field: 'mobile', title: __('Mobile'), operate: false},
                        {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
                        {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {normal: __('Normal'), hidden: __('Hidden')}},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'consume_history_button',
                                    text: '扩展信息',
                                    classname: 'btn btn-xs btn-info btn-addtabs',
                                    url: function (row) {
                                        return Fast.api.fixurl('user/extend?user.username=' + row.username)
                                    },
                                },
                                {
                                    name: 'delivery_address_button',
                                    text: '卡券',
                                    classname: 'btn btn-xs btn-info btn-addtabs',
                                    url: function (row) {
                                        return Fast.api.fixurl('user/card?user.username=' + row.username)
                                    },
                                },
                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ],
                searchFormVisible: true,
                search: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        weixinincome: function () {
            //
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'statistics/weixinIncome',
                    table: '',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormTemplate: 'customformtpl',
                columns: [
                    [
                        {field: 'name', title: '名称'},
                        {field: 'income', title: '金额'},
                        {field: 'note', title: '备注'},
                    ]
                ],
                searchFormVisible: true,
                search: false,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
